//
//  ApplySalesViewController.m
//  ZiJinLian
//
//  Created by 🐛 on 2017/6/2.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "ApplySalesViewController.h"
#import "BuyCountView.h"
#import "ZJDeliveryAddressViewController.h"
#import "AccountViewController.h"

@interface ApplySalesViewController ()<UIScrollViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UITextViewDelegate>
{
    UILabel *name;
    UILabel *phone;
    UILabel *adress;
    UILabel *adresstemp;
}

@property (nonatomic ,strong) UIScrollView *mainScroll;
@property (nonatomic ,strong) UIView *salesView;
@property (nonatomic ,strong) UIView *shopView;
@property (nonatomic ,strong) UIView *numView;
@property (nonatomic ,strong) UIView *questView;
@property (nonatomic ,strong) UIView *imageView;
@property (nonatomic ,strong) UIView *accountView;
@property (nonatomic ,strong) UIView *addressView;
@property (nonatomic ,strong) UIButton *lastBtn;
@property (nonatomic ,strong) UIButton *delete;
@property (nonatomic ,strong) UIButton *chooseImg;
@property (nonatomic ,strong) NSArray *array;
@property (nonatomic ,strong) UILabel *string;
@property (nonatomic ,strong) UITextView  *textView;
@property (nonatomic ,strong) UITextField *count;
@property (nonatomic ,strong) UITextField *bankName;
@property (nonatomic ,strong) UITextField *bankUser;
@property (nonatomic ,strong) UITextField *bankNum;
@property (nonatomic ,strong) NSMutableArray *imagArry;
@property (nonatomic ,strong) UIImageView *imge;
@property (nonatomic ,strong) UIScrollView *scroll;
@property (nonatomic ,strong) NSString *urlString;
@property (nonatomic ,assign) NSInteger salesType;
@property(nonatomic,strong)NSString *province;//addressId;
@property(nonatomic,strong)NSString *city;//addressId;
@property(nonatomic,strong)NSString *district;//addressId;
@property(nonatomic,strong)NSString *detail;//addressId;
@property(nonatomic,strong)NSString *consigneeName;//addressId;
@property(nonatomic,strong)NSString *consigneePhone;//addressId;


@end

@implementation ApplySalesViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //增加监听，当键盘出现或改变时收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
    
    //增加监听，当键退出时收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
    self.imagArry=[NSMutableArray array];
    self.array=[NSArray arrayWithObjects:MyString(@"退货流程"),MyString(@"换货流程"),MyString(@"补货流程"), nil];
    self.title=MyString(@"申请售后");
    [self.view addSubview:[self mainScroll]];
    [self stupSalesView];
    [self exditView];
    // Do any additional setup after loading the view.
}


-(UIScrollView *)mainScroll{
    if (!_mainScroll) {
        _mainScroll=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, MainW, MainH-64-50)];
        _mainScroll.backgroundColor=Gray_Color;
        _mainScroll.contentSize=CGSizeMake(MainW, 775);
        _mainScroll.delegate=self;
        
    }
    return _mainScroll;
}

-(void)stupSalesView{
    UIButton *MySureBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, MainH-64-50, MainW, 50)];
    [MySureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [MySureBtn setTitle:MyString(@"提交") forState:UIControlStateNormal];
    [MySureBtn addTarget:self action:@selector(upLoadClick) forControlEvents:UIControlEventTouchUpInside];
    [MySureBtn setBackgroundColor:Red_Color];
    [self.view addSubview:MySureBtn];
    //商品视图
    self.shopView=[[UIView alloc]init];
    self.shopView.frame=CGRectMake(0, 0, MainW, 100);
    self.shopView.backgroundColor=[UIColor whiteColor];
    [_mainScroll addSubview:self.shopView];
    UIImageView *shopImg=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 80, 80)];
    [shopImg sd_setImageWithURL:[NSURL URLWithString:self.goodsDic[@"imageUrl"]] placeholderImage:[UIImage imageNamed:@"placeholderImage"]];
    [self.shopView addSubview:shopImg];
    UILabel *shopLab=[[UILabel alloc]initWithFrame:CGRectMake(shopImg.bsg_right+10, 15, MainW-100, 15)];
    shopLab.text=[NSString stringWithFormat:@"%@",self.goodsDic[@"spuName"]];
    shopLab.font=[UIFont systemFontOfSize:14];
    shopLab.textColor=TextColor3;
    [self.shopView addSubview:shopLab];
    UILabel *shopType=[[UILabel alloc]initWithFrame:CGRectMake(shopImg.bsg_right+10, shopLab.bsg_bottom+10, MainW-100, 15)];
    shopType.text=self.goodsDic[@"saleName"];
    shopType.font=[UIFont systemFontOfSize:12];
    shopType.textColor=TextColor6;
    [self.shopView addSubview:shopType];
    UILabel *numLab=[[UILabel alloc]initWithFrame:CGRectMake(shopImg.bsg_right+10, shopType.bsg_bottom+10, MainW-100, 15)];
    numLab.text=[NSString stringWithFormat:@"%@ : ×%@",MyString(@"数量"),self.goodsDic[@"quantity"]];
    numLab.font=[UIFont systemFontOfSize:12];
    numLab.textColor=TextColor6;
    [self.shopView addSubview:numLab];
    //服务类型视图
    self.salesView=[[UIView alloc]init];
    self.salesView.frame=CGRectMake(0, self.shopView.bsg_bottom+10, MainW, 65);
    if (self.lastBtn!=nil) {
        self.salesView.frame=CGRectMake(0, self.shopView.bsg_bottom+10, MainW, 100);
    }
    self.salesView.backgroundColor=[UIColor whiteColor];
    [_mainScroll addSubview:self.salesView];
    UILabel *titlelab=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, MainW-100, 15)];
    titlelab.text=MyString(@"服务类型");
    titlelab.font=[UIFont systemFontOfSize:14];
    titlelab.textColor=TextColor3;
    [self.salesView addSubview:titlelab];
    NSArray *array=[NSArray arrayWithObjects:MyString(@"退货"),MyString(@"换货"),MyString(@"补货"), nil];
    for (int i=0; i<array.count; i++) {
        UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(10+60*i, titlelab.bsg_bottom+10, 50, 20)];
        [btn setTitle:array[i] forState:UIControlStateNormal];
        btn.titleLabel.font=[UIFont systemFontOfSize:14];
        [btn setTitleColor:TextColor3 forState:UIControlStateNormal];
        [btn setTitleColor:Red_Color forState:UIControlStateSelected];
        btn.layer.borderWidth=0.5;
        btn.layer.borderColor=TextColor9.CGColor;
        ViewRadius(btn, 2);
        btn.tag=i;
        [btn addTarget:self action:@selector(salesClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.salesView addSubview:btn];
    }
    self.string=[[UILabel alloc]init];
    self.string.frame=CGRectMake(10, titlelab.bsg_bottom+40, MainW-20, 0);
    self.string.numberOfLines=0;
    self.string.textColor=TextColor6;
    //self.string.hidden=YES;
    self.string.font=[UIFont systemFontOfSize:12];
    [self.salesView addSubview:self.string];
    //申请数量类型
    self.numView=[[UIView alloc]init];
    self.numView.frame=CGRectMake(0, self.salesView.bsg_bottom+10, MainW, 75);
    self.numView.backgroundColor=[UIColor whiteColor];
    [_mainScroll addSubview:self.numView];
    MYLabel *numlab=[[MYLabel alloc]initWithFrame:CGRectMake(10, 10, MainW-20, 20)];
    numlab.text=MyString(@"申请数量");
    numlab.textColor=TextColor3;
    [self.numView addSubview:numlab];
    UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(10, numlab.bsg_bottom+10, 25, 25)];
    [btn setTitle:@"-" forState:UIControlStateNormal];
    [btn setTitleColor:TextColor6 forState:UIControlStateNormal];
    btn.layer.borderWidth=1;
    btn.layer.borderColor=SeparatorColor.CGColor;
    [btn addTarget:self action:@selector(reduceClcik) forControlEvents:UIControlEventTouchUpInside];
    [self.numView addSubview:btn];
    self.count=[[UITextField alloc]initWithFrame:CGRectMake(btn.bsg_right-1, numlab.bsg_bottom+10, 30, 25)];
    self.count.text=@"1";
    self.count.textAlignment=1;
    self.count.font=[UIFont systemFontOfSize:14];
    self.count.textColor=TextColor3;
    self.count.keyboardType=UIKeyboardTypeNumberPad;
    self.count.layer.borderWidth=1;
    self.count.layer.borderColor=SeparatorColor.CGColor;
    [self.numView addSubview:self.count];
    UIButton *addbtn=[[UIButton alloc]initWithFrame:CGRectMake(self.count.bsg_right-1, numlab.bsg_bottom+10, 25, 25)];
    [addbtn setTitle:@"+" forState:UIControlStateNormal];
    [addbtn setTitleColor:TextColor6 forState:UIControlStateNormal];
    addbtn.layer.borderWidth=1;
    addbtn.layer.borderColor=SeparatorColor.CGColor;
    [addbtn addTarget:self action:@selector(addClcik) forControlEvents:UIControlEventTouchUpInside];
    [self.numView addSubview:addbtn];
    //地址视图
    self.addressView=[[UIView alloc]init];
    self.addressView.frame=CGRectMake(0, self.numView.bsg_bottom+10, MainW, 120);
    self.addressView.backgroundColor=[UIColor whiteColor];
    [_mainScroll addSubview:self.addressView];
    MYLabel*dresLab=[[MYLabel alloc]initWithFrame:CGRectMake(10, 10, MainW-20, 20)];
    dresLab.text=MyString(@"确定收货信息");
    dresLab.textColor=TextColor3;
    [self.addressView addSubview:dresLab];
    UIView*dline=[[UIView alloc]initWithFrame:CGRectMake(0, dresLab.bsg_bottom+10, MainW, 1)];
    dline.backgroundColor=Gray_Color;
    [self.addressView addSubview:dline];
    name=[[UILabel alloc]initWithFrame:CGRectMake(10, dline.bsg_bottom+10, MainW/2, 15)];
    
    name.textColor=TextColor6;
    name.font=[UIFont systemFontOfSize:12];
    [self.addressView addSubview:name];
    phone=[[UILabel alloc]initWithFrame:CGRectMake(name.bsg_right+10, dline.bsg_bottom+10, MainW/2-70, 15)];
    
    phone.textColor=TextColor6;
    phone.textAlignment=NSTextAlignmentRight;
    phone.font=[UIFont systemFontOfSize:12];
    [self.addressView addSubview:phone];
    adress=[[UILabel alloc]init];
    CGFloat dheight=[ZJUITools getHeightByWidth:MainW-20 title:adress.text font:[UIFont systemFontOfSize:12]];
    adress.frame=CGRectMake(10, phone.bsg_bottom+10, MainW-60, dheight+10);
    adress.textColor=TextColor6;
    adress.numberOfLines=0;
    //adress.textAlignment=NSTextAlignmentRight;
    adress.font=[UIFont systemFontOfSize:12];
    [self.addressView addSubview:adress];
    adresstemp=[[UILabel alloc]initWithFrame:CGRectMake(10, dline.bsg_bottom+1, MainW-27, 80)];
    adresstemp.text=@"暂无收货地址,请选择收货地址!";
    adresstemp.textColor=TextColor6;
    adresstemp.textAlignment=0;
    adresstemp.font=[UIFont systemFontOfSize:12];
    //adresstemp.backgroundColor=[UIColor redColor];
    [self.addressView addSubview:adresstemp];
    UIImageView*imag=[[UIImageView alloc]initWithFrame:CGRectMake(MainW-17, 30+45-6, 7, 12)];
    imag.image=[UIImage imageNamed:@"icon_arrow_right"];
    [self.addressView addSubview:imag];
    UIButton * arrow=[[UIButton alloc]initWithFrame:CGRectMake(0, 30, MainW, 90)];
    //[arrow setImage:[UIImage imageNamed:@"icon_arrow_right"] forState:UIControlStateNormal];
    [arrow addTarget:self action:@selector(chooseAddress) forControlEvents:UIControlEventTouchUpInside];
    [self.addressView addSubview:arrow];
    if (![self.dataDic[@"buyerAddress"] isEqual:[NSNull null]]) {
        adresstemp.hidden=YES;
        name.text=[NSString stringWithFormat:@"%@:%@",MyString(@"收货人"),self.dataDic[@"buyerAddress"][@"consigneeName"]];
        phone.text=[NSString stringWithFormat:@"%@",self.dataDic[@"buyerAddress"][@"consigneePhone"]];
        adress.text=[NSString stringWithFormat:@"%@:%@%@", MyString(@"收货地址"),self.dataDic[@"buyerAddress"][@"area"],self.dataDic[@"buyerAddress"][@"detail"]];
        self.province=self.dataDic[@"buyerAddress"][@"area"];
        self.city=self.dataDic[@"buyerAddress"][@"city"];
        self.district=self.dataDic[@"buyerAddress"][@"district"];
        self.detail=self.dataDic[@"buyerAddress"][@"detail"];
        self.consigneeName=self.dataDic[@"buyerAddress"][@"consigneeName"];
        self.consigneePhone=self.dataDic[@"buyerAddress"][@"consigneePhone"];
    }else{
        adresstemp.hidden=NO;
    }
    //账户视图
    self.accountView=[[UIView alloc]init ];
    self.accountView.frame=CGRectMake(0, self.numView.bsg_bottom+10, MainW, 134);
    self.accountView.backgroundColor=[UIColor whiteColor];
    [_mainScroll addSubview:self.accountView];
    MYLabel*titlLab=[[MYLabel alloc]initWithFrame:CGRectMake(10, 10, MainW-27, 20)];
    titlLab.text=MyString(@"退款账户");
    titlLab.textColor=TextColor3;
    [self.accountView addSubview:titlLab];
    UIImageView*imagBank=[[UIImageView alloc]initWithFrame:CGRectMake(MainW-17, 14, 7, 12)];
    imagBank.image=[UIImage imageNamed:@"icon_arrow_right"];
    [self.accountView addSubview:imagBank];
    UIButton*chooseBank=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, MainW, 40)];
    [chooseBank addTarget:self action:@selector(chooseBankClick) forControlEvents:UIControlEventTouchUpInside];
    [self.accountView addSubview:chooseBank];
    UIView*line=[[UIView alloc]initWithFrame:CGRectMake(0, titlLab.bsg_bottom+10, MainW, 1)];
    line.backgroundColor=Gray_Color;
    [self.accountView addSubview:line];
    MYLabel*bank=[[MYLabel alloc]initWithFrame:CGRectMake(10, line.bsg_bottom+5, 90, 20)];
    bank.text=MyString(@"银行");
    bank.textColor=TextColor3;
    [self.accountView addSubview:bank];
    self.bankName=[[UITextField alloc]initWithFrame:CGRectMake(bank.bsg_right, line.bsg_bottom+5, MainW-100, 20)];
    //self.bankName.text=@"招商银行";
    self.bankName.placeholder=MyString(@"银行名称");
    self.bankName.font=[UIFont systemFontOfSize:14];
    self.bankName.textColor=TextColor3;
    [self.accountView addSubview:self.bankName];
    UIView*line1=[[UIView alloc]initWithFrame:CGRectMake(10, bank.bsg_bottom+5, MainW-20, 1)];
    line1.backgroundColor=Gray_Color;
    [self.accountView addSubview:line1];
    MYLabel*bank1=[[MYLabel alloc]initWithFrame:CGRectMake(10, line1.bsg_bottom+5, 90, 20)];
    bank1.text=MyString(@"持卡人");
    bank1.textColor=TextColor3;
    [self.accountView addSubview:bank1];
    self.bankUser=[[UITextField alloc]initWithFrame:CGRectMake(bank1.bsg_right, line1.bsg_bottom+5, MainW-100, 20)];
    //self.bankUser.text=@"包租婆";
    self.bankUser.placeholder=MyString(@"持卡人名称");
    self.bankUser.font=[UIFont systemFontOfSize:14];
    self.bankUser.textColor=TextColor3;
    [self.accountView addSubview:self.bankUser];
    UIView*line2=[[UIView alloc]initWithFrame:CGRectMake(10, bank1.bsg_bottom+5, MainW-20, 1)];
    line2.backgroundColor=Gray_Color;
    [self.accountView addSubview:line2];
    MYLabel*bank2=[[MYLabel alloc]initWithFrame:CGRectMake(10, line2.bsg_bottom+5, 90, 20)];
    bank2.text=MyString(@"银行卡号");
    bank2.textColor=TextColor3;
    [self.accountView addSubview:bank2];
    self.bankNum=[[UITextField alloc]initWithFrame:CGRectMake(bank2.bsg_right, line2.bsg_bottom+5, MainW-100, 20)];
    //self.bankNum.text=@"招商银行";
    self.bankNum.placeholder=MyString(@"卡号");
    self.bankNum.keyboardType=UIKeyboardTypeNumberPad;
    self.bankNum.font=[UIFont systemFontOfSize:14];
    self.bankNum.textColor=TextColor3;
    [self.accountView addSubview:self.bankNum];
    
    //问题视图
    self.questView=[[UIView alloc]init ];
    self.questView.frame=CGRectMake(0, self.accountView.bsg_bottom+10, MainW, 130);
    self.questView.backgroundColor=[UIColor whiteColor];
    [_mainScroll addSubview:self.questView];
    
    MYLabel*quesLab=[[MYLabel alloc]initWithFrame:CGRectMake(10, 10, MainW-20, 20)];
    quesLab.text=MyString(@"问题描述");
    quesLab.textColor=TextColor3;
    [self.questView addSubview:quesLab];
    UIView*l=[[UIView alloc]initWithFrame:CGRectMake(0, quesLab.bsg_bottom+10, MainW, 1)];
    l.backgroundColor=Gray_Color;
    [self.questView addSubview:l];
    self.textView=[[UITextView alloc]initWithFrame:CGRectMake(10, l.bsg_bottom+10, MainW-20, 80)];
    self.textView.text=MyString(@"输入问题");
    self.textView.delegate=self;
    self.textView.textColor=TextColor9;
    [self.questView addSubview:self.textView];
    //上传照片视图
    NSString*string=MyString(@"照片说明");
    CGFloat height =[ZJUITools getHeightByWidth:MainW-20 title:string font:FontAndStyle12];
    self.imageView=[[UIView alloc]init];
   self.imageView.frame=CGRectMake(0, self.questView.bsg_bottom+10, MainW, 145+height);
    self.imageView.backgroundColor=[UIColor whiteColor];
    [_mainScroll addSubview:self.imageView];
    MYLabel*imgLab=[[MYLabel alloc]initWithFrame:CGRectMake(10, 10, MainW-20, 20)];
    imgLab.text=MyString(@"上传照片");
    imgLab.textColor=TextColor3;
    [self.imageView addSubview:imgLab];
    UIView*lin=[[UIView alloc]initWithFrame:CGRectMake(0, imgLab.bsg_bottom+9, MainW, 1)];
    lin.backgroundColor=Gray_Color;
    [self.imageView addSubview:lin];
    self.scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 40, MainW, 90)];
    self.scroll.backgroundColor=[UIColor whiteColor];
    self.scroll.contentSize=CGSizeMake(MainW, 80);
    [self.imageView addSubview:self.scroll];
    self.chooseImg=[[UIButton alloc]initWithFrame:CGRectMake(10, 10, 80, 80)];
    [self.chooseImg setBackgroundImage:[UIImage imageNamed:@"Image"] forState:UIControlStateNormal];
    [self.chooseImg addTarget:self action:@selector(chooseImageClick) forControlEvents:UIControlEventTouchUpInside];
    [self.scroll addSubview:self.chooseImg];
    UILabel *labek=[[UILabel alloc]initWithFrame:CGRectMake(10, self.scroll.bsg_bottom+10, MainW-20, height)];
    labek.text=string;
    labek.numberOfLines=0;
    labek.font=[UIFont systemFontOfSize:12];
    labek.textColor=TextColor9;
    [self.imageView addSubview:labek];
    UILabel *inslabel=[[UILabel alloc]initWithFrame:CGRectMake(10, labek.bsg_bottom+10, MainW-20, 15)];
    inslabel.textColor=Red_Color;
    inslabel.text=MyString(@"申请说明");
    inslabel.font=[UIFont systemFontOfSize:12];
    [self.imageView addSubview:inslabel];
    
}
#pragma mark - UITextViewDelegate
- (void)textViewDidEndEditing:(UITextView *)textView
{
    if(textView.text.length < 1){
        textView.text = MyString(@"输入问题");
        textView.textColor = TextColor9;
    }
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if([textView.text isEqualToString:MyString(@"输入问题")]){
        textView.text=@"";
        textView.textColor=TextColor3;
    }
}
-(void)salesClick:(UIButton *)sender{
    if (sender.tag==0) {
        self.salesType=0;
        self.urlString=[NSString stringWithFormat:@"%@%@",baseURL,API_APPLYSALESTUN];
    }else if (sender.tag==1){
        self.salesType=1;
        self.urlString=[NSString stringWithFormat:@"%@%@",baseURL,API_APPLYSALESHUAN];
    }else{
        self.salesType=2;
        self.urlString=[NSString stringWithFormat:@"%@%@",baseURL,API_APPLYSALESBU];
    }
    if (self.lastBtn==nil) {
        self.lastBtn=sender;
        sender.layer.borderColor=Red_Color.CGColor;
        [sender setTitleColor:Red_Color forState:UIControlStateNormal];
    }else{
        if (sender!=self.lastBtn) {
            self.lastBtn.layer.borderColor=TextColor3.CGColor;
            [self.lastBtn setTitleColor:TextColor3 forState:UIControlStateNormal];
            sender.layer.borderColor=Red_Color.CGColor;
            [sender setTitleColor:Red_Color forState:UIControlStateNormal];
            self.lastBtn=sender;
        }
    }
    self.string.text=self.array[self.lastBtn.tag];
    CGFloat height =[ZJUITools getHeightByWidth:MainW-20 title:self.string.text font:FontAndStyle12];
    [self refreshViewFram:height NSIndex:sender.tag];
}
-(void)refreshImagView:(NSMutableArray *)imagArray{
    for(UIView *view in [self.scroll subviews])
    {
        [view removeFromSuperview];
    }
    for (int i=0; i<imagArray.count; i++) {
        self.imge=[[UIImageView alloc]initWithFrame:CGRectMake(10+90*i, 10, 80, 80)];
        self.imge.image=imagArray[i];
        [self.scroll addSubview: self.imge];
       self.delete=[[UIButton alloc]initWithFrame:CGRectMake(85+90*i, 5, 10, 10)];
        [self.delete setBackgroundImage:[UIImage imageNamed:@"icon_closeimg"] forState:UIControlStateNormal];
        self.delete.tag=i;
        [self.delete addTarget:self action:@selector(deleteClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.scroll addSubview:self.delete];
    }
    self.chooseImg.frame=CGRectMake(10+90*imagArray.count, 10, 80, 80);
    [self.scroll addSubview:self.chooseImg];
    if ((10+90*imagArray.count)>(MainW-100)) {
        self.scroll.contentSize=CGSizeMake((10+90*imagArray.count)+100, 80);
    }
    if (self.imagArry.count==5) {
        self.chooseImg.hidden=YES;
        self.scroll.contentSize=CGSizeMake(460, 80);
    }else{
        self.chooseImg.hidden=NO;
    }
}
-(void)refreshViewFram:(CGFloat)height NSIndex:(NSInteger)index{
    switch (index) {
        case 0:
        {
            self.accountView.hidden=NO;
            self.addressView.hidden=YES;
            self.mainScroll.contentSize=CGSizeMake(MainW, 785+height);
            self.salesView.frame=CGRectMake(0, self.shopView.bsg_bottom+10, MainW, 75+height);
            self.string.frame=CGRectMake(10, 65, MainW-20, height);
            self.numView.frame=CGRectMake(0, self.salesView.bsg_bottom+10, MainW, 75);
            self.accountView.frame=CGRectMake(0, self.numView.bsg_bottom+10, MainW, 134);
            self.questView.frame=CGRectMake(0, self.accountView.bsg_bottom+10, MainW, 130);
            self.imageView.frame=CGRectMake(0, self.questView.bsg_bottom+10, MainW, 180);
        }
            break;
        case 1:
        {
            self.accountView.hidden=YES;
            self.addressView.hidden=NO;
            self.mainScroll.contentSize=CGSizeMake(MainW, 770+height);
            self.salesView.frame=CGRectMake(0, self.shopView.bsg_bottom+10, MainW, 75+height);
            self.string.frame=CGRectMake(10, 65, MainW-20, height);
            self.numView.frame=CGRectMake(0, self.salesView.bsg_bottom+10, MainW, 75);
            self.addressView.frame=CGRectMake(0, self.numView.bsg_bottom+10, MainW, 120);
            self.questView.frame=CGRectMake(0, self.addressView.bsg_bottom+10, MainW, 130);
            self.imageView.frame=CGRectMake(0, self.questView.bsg_bottom+10, MainW, 180);
        }
            break;
        case 2:
        {
            self.accountView.hidden=YES;
            self.addressView.hidden=NO;
            self.mainScroll.contentSize=CGSizeMake(MainW, 770+height);
            self.salesView.frame=CGRectMake(0, self.shopView.bsg_bottom+10, MainW, 75+height);
            self.string.frame=CGRectMake(10, 65, MainW-20, height);
            self.numView.frame=CGRectMake(0, self.salesView.bsg_bottom+10, MainW, 75);
            self.addressView.frame=CGRectMake(0, self.numView.bsg_bottom+10, MainW, 120);
            self.questView.frame=CGRectMake(0, self.addressView.bsg_bottom+10, MainW, 130);
            self.imageView.frame=CGRectMake(0, self.questView.bsg_bottom+10, MainW, 180);
        }
            break;
            
        default:
            break;
    }
    
}
//减
-(void)reduceClcik{
    [self.count resignFirstResponder];
    if ([self.count.text intValue]<=1) {
        [self showHint:MyString(@"数量超出范围~")];
    }else{
        self.count.text=[NSString stringWithFormat:@"%d",[self.count.text intValue]-1];
    }
    
}
//加
-(void)addClcik{
    [self.count resignFirstResponder];
    if ([self.count.text intValue]>([self.goodsDic[@"number"] intValue]-1)) {
        [self showHint:MyString(@"数量超出范围~")];
    }else{
        self.count.text=[NSString stringWithFormat:@"%d",[self.count.text intValue]+1];
    }
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.count resignFirstResponder];
}
//ti提交
-(void)upLoadClick{
    if (self.urlString==nil) {
        [self showToast:MyString(@"服务说明")];
        return;
    }
    if (self.imagArry.count==0) {
        [self showToast:MyString(@"提交说明")];
        return;
    }
    [self Returngoods];
}
//选择照片
-(void)chooseImageClick{
    
    UIAlertController* alertC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    /*UIAlertControllerStyleActionSheet  警告框的样式:底部*/
    [alertC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
    [alertC addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self takePhoto]; /*拍照*/
    }]];
    [alertC addAction:[UIAlertAction actionWithTitle:@"我的相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self LocalPhoto]; /*从相册*/
    }]];
    
    [self presentViewController:alertC animated:YES completion:nil];
}
/**
 * 从相册选择
 */
-(void)LocalPhoto
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    //资源类型为图片库
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    //设置选择后的图片可被编辑
    picker.allowsEditing = YES;
    [self presentViewController:picker animated:YES completion:nil];
}

/**
 * 拍照
 */
-(void)takePhoto
{
    //资源类型为照相机
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    //判断是否有相机
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
    {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        //设置拍照后的图片可被编辑
        picker.allowsEditing = YES;
        //资源类型为照相机
        picker.sourceType = sourceType;
        [self presentViewController:picker animated:YES completion:nil];
    }else
    {
        [self showToast:@"该设备无摄像头"]; //跳出提示
    }
}
/**
 * 图像选取器的委托方法，选完图片后回调该方法
 */
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    //当图片不为空时显示图片并保存图片
    if (image!= nil)
    {
        [self.imagArry addObject:image];
        [self refreshImagView:self.imagArry];
        //关闭相册界面
        [picker dismissViewControllerAnimated:YES completion:nil];
    }
    
}
// 相机选择取消按钮
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:nil];
}

- (void)changeFaceImg:(NSString *)userimg small:(NSString *)userlittleimg userid:(NSString *)userid
{
    
    
}
-(void)deleteClick:(UIButton *)sender{
    [self.imagArry removeObjectAtIndex:sender.tag];
    [self refreshImagView:self.imagArry];
}
//选择地址
-(void)chooseAddress{
    ZJDeliveryAddressViewController*vc=[[ZJDeliveryAddressViewController alloc]init];
    vc.styple=1;
    vc.addressBlock=^(ZJAdressModel *model){
        adresstemp.hidden=YES;
        name.text=[NSString stringWithFormat:@"%@:%@",MyString(@"收货人"),model.consigneeName];
        phone.text=[NSString stringWithFormat:@"%@",model.consigneePhone];
        self.province=model.province;
        self.city=model.city;
        self.detail=model.detail;
        self.district=model.district;
        self.consigneePhone=model.consigneePhone;
        self.consigneeName=model.consigneeName;
        NSString* str=[NSString stringWithFormat:@"%@%@",[model.area stringByReplacingOccurrencesOfString:@" " withString:@""],model.detail];
        if (model.isDefault==1) {//默认
            NSMutableAttributedString *str2 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@",@"[默认地址]",str]];
            [str2 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,6)];
            adress.attributedText=str2;
        }else{
            adress.text=[NSString stringWithFormat:@"%@:%@",MyString(@"收货地址"),str];
        }
        
    };
    [self.navigationController pushViewController:vc  animated:YES];
}
-(void)Returngoods{
    [self showDialog];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",
                                                         
                                                         @"text/html",
                                                         
                                                         @"image/jpeg",
                                                         
                                                         @"image/png",
                                                         
                                                         @"application/octet-stream",
                                                         
                                                         @"text/json",
                                                         
                                                         nil];
    [manager POST:self.urlString parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        // 上传的参数名
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        formatter.dateFormat = @"yyyyMMddHHmmss";
        NSString *str = [formatter stringFromDate:[NSDate date]];
        NSString *fileName = [NSString stringWithFormat:@"%@.jpg", str];
        switch (self.imagArry.count) {
            case 1:
            {
                NSData * imageData = UIImageJPEGRepresentation([self.imagArry objectAtIndex: 0], 0.5);
                [formData appendPartWithFileData:imageData name:@"file" fileName:fileName mimeType:@"image/jpeg"];
            }
                break;
                
            case 2:
            {
                NSData * imageData = UIImageJPEGRepresentation([self.imagArry objectAtIndex: 0], 0.5);
                NSData * imageData1 = UIImageJPEGRepresentation([self.imagArry objectAtIndex: 1], 0.5);
                [formData appendPartWithFileData:imageData name:@"file" fileName:fileName mimeType:@"image/jpeg"];
                [formData appendPartWithFileData:imageData1 name:@"file" fileName:fileName mimeType:@"image/jpeg"];
            }
                break;
                
            case 3:
            {
                NSData * imageData = UIImageJPEGRepresentation([self.imagArry objectAtIndex: 0], 0.5);
                [formData appendPartWithFileData:imageData name:@"file" fileName:fileName mimeType:@"image/jpeg"];
                NSData * imageData1 = UIImageJPEGRepresentation([self.imagArry objectAtIndex: 1], 0.5);
                [formData appendPartWithFileData:imageData1 name:@"file" fileName:fileName mimeType:@"image/jpeg"];
                NSData * imageData2 = UIImageJPEGRepresentation([self.imagArry objectAtIndex: 2], 0.5);
                [formData appendPartWithFileData:imageData2 name:@"file" fileName:fileName mimeType:@"image/jpeg"];
            }
                break;
                
            case 4:
            {
                NSData * imageData = UIImageJPEGRepresentation([self.imagArry objectAtIndex: 0], 0.5);
                [formData appendPartWithFileData:imageData name:@"file" fileName:fileName mimeType:@"image/jpeg"];
                NSData * imageData1 = UIImageJPEGRepresentation([self.imagArry objectAtIndex: 1], 0.5);
                [formData appendPartWithFileData:imageData1 name:@"file" fileName:fileName mimeType:@"image/jpeg"];
                NSData * imageData2 = UIImageJPEGRepresentation([self.imagArry objectAtIndex: 2], 0.5);
                [formData appendPartWithFileData:imageData2 name:@"file" fileName:fileName mimeType:@"image/jpeg"];
                NSData * imageData3 = UIImageJPEGRepresentation([self.imagArry objectAtIndex: 3], 0.5);
                [formData appendPartWithFileData:imageData3 name:@"file" fileName:fileName mimeType:@"image/jpeg"];
            }
                break;
                
            case 5:
            {
                NSData * imageData = UIImageJPEGRepresentation([self.imagArry objectAtIndex: 0], 0.5);
                [formData appendPartWithFileData:imageData name:@"file" fileName:fileName mimeType:@"image/jpeg"];
                NSData * imageData1 = UIImageJPEGRepresentation([self.imagArry objectAtIndex: 1], 0.5);
                [formData appendPartWithFileData:imageData1 name:@"file" fileName:fileName mimeType:@"image/jpeg"];
                NSData * imageData2 = UIImageJPEGRepresentation([self.imagArry objectAtIndex: 2], 0.5);
                [formData appendPartWithFileData:imageData2 name:@"file" fileName:fileName mimeType:@"image/jpeg"];
                NSData * imageData3 = UIImageJPEGRepresentation([self.imagArry objectAtIndex: 3], 0.5);
                [formData appendPartWithFileData:imageData3 name:@"file" fileName:fileName mimeType:@"image/jpeg"];
                NSData * imageData4= UIImageJPEGRepresentation([self.imagArry objectAtIndex: 4], 0.5);
                [formData appendPartWithFileData:imageData4 name:@"file" fileName:fileName mimeType:@"image/jpeg"];
            }
                break;
                
            default:
                break;
        }
        // 上传 多张图片
       
        if (self.salesType==0) {
            [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",self.goodsDic[@"itemId"]] dataUsingEncoding:NSUTF8StringEncoding] name:@"itemId"];
            [formData appendPartWithFormData:[@"zhcn" dataUsingEncoding:NSUTF8StringEncoding] name:@"lang"];
            [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",self.count.text] dataUsingEncoding:NSUTF8StringEncoding] name:@"number"];
            [formData appendPartWithFormData:[self.textView.text dataUsingEncoding:NSUTF8StringEncoding] name:@"reason"];
            [formData appendPartWithFormData:[self.bankName.text dataUsingEncoding:NSUTF8StringEncoding] name:@"creditBank"];
            [formData appendPartWithFormData:[self.bankNum.text dataUsingEncoding:NSUTF8StringEncoding] name:@"creditCard"];
            [formData appendPartWithFormData:[self.bankUser.text dataUsingEncoding:NSUTF8StringEncoding] name:@"creditName"];
        }else if (self.salesType==1){
            [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",self.goodsDic[@"itemId"]]  dataUsingEncoding:NSUTF8StringEncoding] name:@"itemId"];
            [formData appendPartWithFormData:[@"zhcn" dataUsingEncoding:NSUTF8StringEncoding] name:@"lang"];
            //number  number reason image creditBank creditCard creditName
            [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",self.count.text] dataUsingEncoding:NSUTF8StringEncoding] name:@"number"];
            [formData appendPartWithFormData:[self.textView.text dataUsingEncoding:NSUTF8StringEncoding] name:@"reason"];
            [formData appendPartWithFormData:[self.province dataUsingEncoding:NSUTF8StringEncoding] name:@"province"];
            [formData appendPartWithFormData:[self.detail dataUsingEncoding:NSUTF8StringEncoding] name:@"detail"];
            [formData appendPartWithFormData:[self.city dataUsingEncoding:NSUTF8StringEncoding] name:@"city"];
            [formData appendPartWithFormData:[self.district dataUsingEncoding:NSUTF8StringEncoding] name:@"district"];
            [formData appendPartWithFormData:[self.consigneePhone dataUsingEncoding:NSUTF8StringEncoding] name:@"consigneePhone"];
            [formData appendPartWithFormData:[self.consigneeName dataUsingEncoding:NSUTF8StringEncoding] name:@"consigneeName"];
        }else{
            [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",self.goodsDic[@"itemId"]]  dataUsingEncoding:NSUTF8StringEncoding] name:@"itemId"];
            [formData appendPartWithFormData:[@"zhcn" dataUsingEncoding:NSUTF8StringEncoding] name:@"lang"];
            //number  number reason image creditBank creditCard creditName
            [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",self.count.text] dataUsingEncoding:NSUTF8StringEncoding] name:@"number"];
            [formData appendPartWithFormData:[self.textView.text dataUsingEncoding:NSUTF8StringEncoding] name:@"reason"];
            [formData appendPartWithFormData:[self.province dataUsingEncoding:NSUTF8StringEncoding] name:@"province"];
            [formData appendPartWithFormData:[self.detail dataUsingEncoding:NSUTF8StringEncoding] name:@"detail"];
            [formData appendPartWithFormData:[self.city dataUsingEncoding:NSUTF8StringEncoding] name:@"city"];
            [formData appendPartWithFormData:[self.district dataUsingEncoding:NSUTF8StringEncoding] name:@"district"];
            [formData appendPartWithFormData:[self.consigneePhone dataUsingEncoding:NSUTF8StringEncoding] name:@"consigneePhone"];
            [formData appendPartWithFormData:[self.consigneeName dataUsingEncoding:NSUTF8StringEncoding] name:@"consigneeName"];
        }
        
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [self dismissDialog];
        if ([responseObject[@"status"] intValue]!=0) {
            [self showToast:responseObject[@"msg"]];
        }else{
            [MBProgressHUD showSuccess:@"提交成功!"];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [self.navigationController popViewControllerAnimated:YES];
            });
 
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self dismissDialog];
        [MBProgressHUD showError:@"提交失败!"];
    }];
    
    
    
}
//选择银行卡
-(void)chooseBankClick{
    self.binkOrg=3;
    AccountViewController*vc=[[AccountViewController alloc]init];
    vc.chooseBank = ^(NSDictionary *bankInfo) {
        self.bankUser.text=[NSString stringWithFormat:@"%@",bankInfo[@"creditName"]];
        self.bankName.text=[NSString stringWithFormat:@"%@",bankInfo[@"creditBank"]];
        self.bankNum.text=[NSString stringWithFormat:@"%@",bankInfo[@"creditAccount"]];
    };
    [self.navigationController pushViewController:vc animated:YES];
}
//当键盘出现或改变时调用
- (void)keyboardWillShow:(NSNotification *)aNotification
{
    //获取键盘的高度
//    NSDictionary *userInfo = [aNotification userInfo];
//    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    //CGRect keyboardRect = [aValue CGRectValue];
    //int height = keyboardRect.size.height;
    if (self.urlString==nil) {
        self.mainScroll.contentOffset=CGPointMake(0, 270);
    }else{
        self.mainScroll.contentOffset=CGPointMake(0, 280);
    }
    
}


//当键退出时调用
- (void)keyboardWillHide:(NSNotification *)aNotification{
    //self.alert.showView.frame=CGRectMake(MainW/2-135, MainH/2-95, 270, 190);
    
}
@end
